package com.example.appframework.login.loginmethod;

import androidx.lifecycle.ViewModelProviders;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.appframework.R;
import com.example.appframework.login.LoginMainActivity;

public class LoginMethodFragment extends Fragment {

    private LoginMethodViewModel mViewModel;

    Boolean MethodFlag = true;
    //Boolean phoneFlag = false;


    public static LoginMethodFragment newInstance() {
        return new LoginMethodFragment();
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.login_method_fragment, container, false);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mViewModel = ViewModelProviders.of(this).get(LoginMethodViewModel.class);
        // TODO: Use the ViewModel

        getView().findViewById(R.id.passwordButton).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(!MethodFlag){
                    NavController navController = Navigation.findNavController(getActivity(), R.id.fragmentMethod);
                    navController.navigate(R.id.action_phoneLoginFragment_to_passwordLoginFragment);
                    MethodFlag = true;
                }
            }
        });

        getView().findViewById(R.id.phoneButton).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(MethodFlag){
                    NavController navController = Navigation.findNavController(getActivity(), R.id.fragmentMethod);
                    navController.navigate(R.id.action_passwordLoginFragment_to_phoneLoginFragment);
                    MethodFlag = false;
                }
            }
        });

        getView().findViewById(R.id.buttonRegister).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                NavController navController = Navigation.findNavController(getActivity(),R.id.fragmentLogin);
                navController.navigate(R.id.action_loginMethodFragment_to_createFragment);
            }
        });

        getView().findViewById(R.id.retrievePassword).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                NavController navController = Navigation.findNavController(getActivity(),R.id.fragmentLogin);
                navController.navigate(R.id.action_loginMethodFragment_to_retrievePasswordFragment2);
            }
        });

        getView().findViewById(R.id.modifyPassword).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                NavController navController = Navigation.findNavController(getActivity(),R.id.fragmentLogin);
                navController.navigate(R.id.action_loginMethodFragment_to_modifyPasswordFragment4);
            }
        });
    }

}